# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_0110
from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_1120
from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_2130
from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_3140
from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_4150
from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_2049
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_0110
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_1120
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_2130
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_3140
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_4150
from jms.dwd.dwd_warhouse.dwd_wide_summary_waybill import jms_dwd__dwd_wide_summary_waybill_2049
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from airflow.operators.dummy_operator import DummyOperator

jms_dwd__dwd_wide_trace_waybill_step_dt_0110 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_0110',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_0110_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_0110.sql',
    driver_memory='16G',
    driver_cores=8,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=4,
    executor_memory='20G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 2000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt_1120 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_1120',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_1120_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_1120.sql',
    driver_memory='16G',
    driver_cores=8,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=4,
    executor_memory='20G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 2000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt_2130 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_2130',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_2130_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_2130.sql',
    driver_memory='16G',
    driver_cores=8,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=4,
    executor_memory='20G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 2000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt_3140 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_3140',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_3140_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_3140.sql',
    driver_memory='16G',
    driver_cores=8,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=8,
    executor_memory='20G',
    num_executors=80,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 2000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt_4150 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_4150',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_4150_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_4150.sql',
    driver_memory='16G',
    driver_cores=8,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=4,
    executor_memory='20G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 2000,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt_2049 = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt_2049',
    task_concurrency=1,
    pool_slots=12,
    master='yarn',
    name='jms_dwd__dwd_wide_trace_waybill_step_dt_2049_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_warhouse/dwd_wide_trace_waybill_step_dt/execute_2049.sql',
    driver_memory='12G',
    driver_cores=4,
    retries=1,
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_cores=4,
    executor_memory='15G',
    num_executors=50,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 200,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 100,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '15G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold':104857600,
          'spark.sql.shuffle.partitions': 600,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          '-XX:MaxDirectMemorySize': '40G',
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 1800,  # 每天生成 60 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 60 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_trace_waybill_step_dt = DummyOperator(
    task_id='jms_dwd__dwd_wide_trace_waybill_step_dt',
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    retries=0,
    priority_weight=0,
)

jms_dwd__dwd_wide_trace_waybill_step_dt_0110 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_0110
    ,jms_dwd__dwd_wide_summary_waybill_0110
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt_1120 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_1120
    ,jms_dwd__dwd_wide_summary_waybill_1120
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt_2130 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_2130
    ,jms_dwd__dwd_wide_summary_waybill_2130
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt_3140 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_3140
    ,jms_dwd__dwd_wide_summary_waybill_3140
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt_4150 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_4150
    ,jms_dwd__dwd_wide_summary_waybill_4150
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt_2049 << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_2049
    ,jms_dwd__dwd_wide_summary_waybill_2049
    ,jms_dim__dim_network_whole_massage
    ,jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
]
jms_dwd__dwd_wide_trace_waybill_step_dt << [
    jms_dwd__dwd_wide_trace_waybill_step_dt_0110
    ,jms_dwd__dwd_wide_trace_waybill_step_dt_1120
    ,jms_dwd__dwd_wide_trace_waybill_step_dt_2130
    ,jms_dwd__dwd_wide_trace_waybill_step_dt_3140
    ,jms_dwd__dwd_wide_trace_waybill_step_dt_4150
    ,jms_dwd__dwd_wide_trace_waybill_step_dt_2049
]
